﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace 程序烧写
{
    public partial class Form1 : Form
    {
        byte[] txFrame1;
        byte[] txFrame2;
        byte[] txFrame3;
        byte[] txFrame4;
        byte[] txFrame5;
        byte[] txFrame6;
        byte[] txFrame7;
        byte[] txFrame8;
        byte[] txFrame9;
        byte[] txFrame10;
        byte[] txFrame11;
        byte[] txFrame12;
        byte[] txFrame13;
        byte[] txFrame14;
        byte[] txFrame15;
        byte[] txFrame16;
        byte[] txFrame17;
        byte[] txFrame18;
        byte[] txFrame19;
        byte[] txFrame20;
        byte[] txFrame21;


        byte[] txFrame_File1;
        byte[] txFrame_File2;
        byte[] txFrame_File3;
        byte[] txFrame_File4;
        byte[] txFrame_File5;
        byte[] txFrame_FileParam;
        byte[] txFrame_Start;
        void InitTxData()
        {
            txFrame1 = new byte[] { 0xc0, 0x00, 0x08, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x12, 0x20, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xc0 };
            txFrame2 = new byte[] {0xc0,0x00,0x0a,0x04,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0xf0,0x3f,0xc0};//351
            txFrame3 = new byte[] {0xc0,0x00,0x0a,0x04,0x00,0x00,0x00,0x00,0x00,0x54,0x00,0xf0,0x3f,0xc0};//369
            txFrame4 = new byte[] {0xc0,0x00,0x0a,0x04,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0xf0,0x3f,0xc0};//387
            txFrame5 = new byte[] {0xc0,0x00,0x0a,0x04,0x00,0x00,0x00,0x00,0x00,0x5c,0x00,0xf0,0x3f,0xc0};//405
            txFrame6 = new byte[] {0xc0,0x00,0x0a,0x04,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x60,0xc0};//423
            txFrame7 = new byte[] {0xc0,0x00,0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0xc0};//473
            txFrame8 = new byte[] {0xc0,0x00,0x09,0x10,0x00,0x00,0x00,0x00,0x00,0x40,0x02,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0};//523
            txFrame9 = new byte[] {0xc0,0x00,0x09,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x60,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0xc0};//541
            txFrame10 = new byte[] {0xc0,0x00,0x0a,0x04,0x00,0x00,0x00,0x00,0x00,0x40,0x02,0x00,0x60,0xc0};//559
            txFrame11 = new byte[] {0xc0,0x00,0x0b,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0xff,0xff,0x00,0x00,0xc0};//577
            txFrame12 = new byte[] {0xc0,0x00,0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x0e,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0xc0};//627
            txFrame13 = new byte[] {0xc0,0x00,0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x10,0x01,0x00,0xc0};//709
            txFrame14 = new byte[] {0xc0,0x00,0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x02,0x00,0x6b,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x04,0x00,0xc0};//791
            txFrame15 = new byte[] {0xc0,0x00,0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0xdb,0xdc,0x3f,0x00,0xc0};//873
            txFrame16 = new byte[] {0xc0,0x00,0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0xe0,0x3f,0x00,0xc0};//955
            txFrame17 = new byte[] { 0xc0, 0x00, 0x05, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x9c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0xc0 };//1005
            txFrame18 = new byte[] { 0xc0, 0x00, 0x07, 0xac, 0x07, 0xcd, 0x00, 0x00, 0x00, 0x9c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0x01, 0x00, 0x08, 0x00, 0x00, 0x60, 0x1c, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x60, 0x31, 0xfc, 0xff, 0x71, 0xfc, 0xff, 0x81, 0xfc, 0xff, 0xdb, 0xdc, 0x20, 0x00, 0x68, 0x03, 0x32, 0xd2, 0x10, 0xdb, 0xdc, 0x20, 0x00, 0x48, 0x07, 0x40, 0x40, 0x74, 0xdc, 0xc4, 0x86, 0x08, 0x00, 0x58, 0x23, 0xdb, 0xdc, 0x20, 0x00, 0x98, 0x08, 0x1b, 0xa5, 0xa9, 0x23, 0x92, 0x45, 0x00, 0x58, 0x03, 0x1b, 0x55, 0x59, 0x03, 0x58, 0x23, 0x37, 0x35, 0x01, 0x29, 0x23, 0x0b, 0x44, 0x66, 0x04, 0xdf, 0xc6, 0xf3, 0xff, 0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08, 0x31, 0x2d, 0x0c, 0xd8, 0x11, 0xc8, 0x21, 0xe8, 0x01, 0x12, 0xc1, 0x10, 0x0d, 0xf0, 0x00, 0x0c, 0x10, 0x00, 0x00, 0x14, 0x00, 0x10, 0x40, 0x0c, 0x00, 0x00, 0x60, 0x74, 0x10, 0x00, 0x00, 0x64, 0x10, 0x00, 0x00, 0x80, 0x10, 0x00, 0x00, 0x8c, 0x10, 0x00, 0x00, 0x84, 0x10, 0x00, 0x00, 0x88, 0x10, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x18, 0x98, 0x00, 0x40, 0x88, 0x0f, 0x00, 0x40, 0xa8, 0x0f, 0x00, 0x40, 0x34, 0x98, 0x00, 0x40, 0x4c, 0x4a, 0x00, 0x40, 0x74, 0x0f, 0x00, 0x40, 0x80, 0x0f, 0x00, 0x40, 0x98, 0x0f, 0x00, 0x40, 0x00, 0x99, 0x00, 0x40, 0x12, 0xc1, 0xe0, 0x91, 0xf5, 0xff, 0xc9, 0x61, 0xcd, 0x02, 0x21, 0xef, 0xff, 0xe9, 0x41, 0xf9, 0x31, 0x09, 0x71, 0xd9, 0x51, 0x90, 0x11, 0xdb, 0xdc, 0x1a, 0x22, 0x39, 0x02, 0xe2, 0xd1, 0x10, 0x0c, 0x02, 0x22, 0x6e, 0x1d, 0x21, 0xe4, 0xff, 0x31, 0xe9, 0xff, 0x2a, 0xf1, 0x1a, 0x33, 0x2d, 0x0f, 0x42, 0x63, 0x00, 0x01, 0xea, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0xdb, 0xdc, 0x30, 0xb4, 0x3c, 0x22, 0x56, 0xa3, 0x16, 0x21, 0xe1, 0xff, 0x1a, 0x22, 0x28, 0x02, 0x20, 0x30, 0xb4, 0x3c, 0x32, 0x56, 0xb3, 0x15, 0x01, 0xad, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0xdd, 0x02, 0x3c, 0x42, 0x56, 0xed, 0x14, 0x31, 0xd6, 0xff, 0x4d, 0x01, 0x0c, 0x52, 0xd9, 0x0e, 0x19, 0x2e, 0x12, 0x6e, 0x01, 0x01, 0xdd, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x21, 0xd2, 0xff, 0x32, 0xa1, 0x01, 0xdb, 0xdc, 0x20, 0x00, 0x48, 0x02, 0x30, 0x34, 0x20, 0xdb, 0xdc, 0x20, 0x00, 0x39, 0x02, 0x2c, 0x02, 0x01, 0xd7, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x46, 0x33, 0x00, 0x00, 0x00, 0x31, 0xcd, 0xff, 0x1a, 0x33, 0x38, 0x03, 0xd0, 0x23, 0xdb, 0xdc, 0x31, 0x99, 0xff, 0x27, 0xb3, 0x1a, 0xdc, 0x7f, 0x31, 0xcb, 0xff, 0x1a, 0x33, 0x28, 0x03, 0x01, 0x98, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x56, 0xc2, 0x0e, 0x21, 0x93, 0xff, 0x2a, 0xdd, 0x06, 0x0e, 0x00, 0x00, 0x31, 0xc6, 0xff, 0x1a, 0x33, 0x28, 0x03, 0x01, 0x91, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x56, 0x82, 0x0d, 0xd2, 0xdd, 0x10, 0x46, 0x08, 0x00, 0x00, 0x00, 0x21, 0xbe, 0xff, 0x1a, 0x22, 0x28, 0x02, 0x9c, 0xe2, 0x31, 0xbc, 0xff, 0xdb, 0xdc, 0x20, 0xf5, 0x1a, 0x33, 0x29, 0x03, 0x31, 0xbb, 0xff, 0xdb, 0xdc, 0x2c, 0x41, 0x1a, 0x33, 0x29, 0x03, 0xdb, 0xdc, 0xf0, 0xf4, 0x22, 0x2e, 0x1d, 0x22, 0xd2, 0x04, 0x27, 0x3d, 0x93, 0x32, 0xa3, 0xff, 0xdb, 0xdc, 0x20, 0x00, 0x28, 0x0e, 0x27, 0xb3, 0xf7, 0x21, 0xab, 0xff, 0x38, 0x1e, 0x1a, 0x22, 0x42, 0xa4, 0x00, 0x01, 0xb5, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x38, 0x1e, 0x2d, 0x0c, 0x42, 0xa4, 0x00, 0x01, 0xb3, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x56, 0x12, 0x08, 0x01, 0xb2, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0xdb, 0xdc, 0x20, 0x00, 0x28, 0x0e, 0xc2, 0xdc, 0x04, 0x22, 0xd2, 0xfc, 0xdb, 0xdc, 0x20, 0x00, 0x29, 0x0e, 0x01, 0xad, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x22, 0x2e, 0x1d, 0x22, 0xd2, 0x04, 0x22, 0x6e, 0x1d, 0x28, 0x1e, 0x22, 0xd2, 0x04, 0xe7, 0xb2, 0x04, 0x29, 0x1e, 0x86, 0x00, 0x00, 0x12, 0x6e, 0x01, 0x21, 0x98, 0xff, 0x32, 0xa0, 0x04, 0x2a, 0x21, 0x05, 0x43, 0x00, 0x31, 0x98, 0xff, 0x22, 0x2e, 0x1d, 0x1a, 0x33, 0x38, 0x03, 0x37, 0xb2, 0x02, 0xc6, 0xd6, 0xff, 0x2c, 0x02, 0x01, 0x9f, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x21, 0x91, 0xff, 0x31, 0x8c, 0xff, 0x1a, 0x22, 0x3a, 0x31, 0x01, 0x9c, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x21, 0x8d, 0xff, 0x1c, 0x03, 0x1a, 0x22, 0x05, 0x40, 0x00, 0x0c, 0x02, 0x06, 0x03, 0x00, 0x00, 0x3c, 0x52, 0x86, 0x01, 0x00, 0x3c, 0x62, 0x46, 0x00, 0x00, 0x3c, 0x72, 0x91, 0x8b, 0xff, 0x9a, 0x11, 0x08, 0x71, 0xc8, 0x61, 0xd8, 0x51, 0xe8, 0x41, 0xf8, 0x31, 0x12, 0xc1, 0x20, 0x0d, 0xf0, 0x00, 0x10, 0x00, 0x00, 0x58, 0x10, 0x00, 0x00, 0xb0, 0x10, 0x00,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c, 0x10, 0x00, 0x00, 0xd0, 0x10, 0x00, 0x00, 0x12, 0xc1, 0xe0, 0x91, 0xfe, 0xff, 0xc9, 0x61, 0xd9, 0x51, 0xe9, 0x41, 0x09, 0x71, 0xf9, 0x31, 0xcd, 0x03, 0x90, 0x11, 0xdb, 0xdc, 0xed, 0x02, 0xdd, 0x04, 0x31, 0xc8, 0xff, 0x9c, 0x14, 0x22, 0xa0, 0x62, 0x47, 0xb3, 0x02, 0x06, 0x2d, 0x00, 0x21, 0xf4, 0xff, 0x1a, 0x22, 0x49, 0x02, 0x86, 0x01, 0x00, 0x21, 0xf1, 0xff, 0x1a, 0x22, 0x39, 0x02, 0x21, 0xc2, 0xff, 0x2a, 0xf1, 0x2d, 0x0f, 0x01, 0x46, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x46, 0x1c, 0x00, 0x22, 0xd1, 0x10, 0x01, 0x43, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x21, 0xe9, 0xff, 0xfd, 0x0c, 0x1a, 0x22, 0x28, 0x02, 0xc7, 0xb2, 0x06, 0x21, 0xe6, 0xff, 0x1a, 0x22, 0xf8, 0x02, 0x2d, 0x0e, 0x3d, 0x01, 0x4d, 0x0f, 0x01, 0xb7, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x8c, 0x52, 0x22, 0xa0, 0x63, 0xc6, 0x18, 0x00, 0x00, 0x21, 0xb1, 0xff, 0x3d, 0x01, 0x10, 0x22, 0x80, 0xf0, 0x4f, 0x20, 0x01, 0x38, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0xac, 0x7d, 0x22, 0xd1, 0x10, 0x3d, 0x01, 0x4d, 0x0f, 0x01, 0x34, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x21, 0xaa, 0xff, 0x32, 0xd1, 0x10, 0x10, 0x22, 0x80, 0x01, 0x35, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x21, 0xa7, 0xff, 0x1c, 0x03, 0x1a, 0x22, 0x01, 0xa7, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0xfa, 0xee, 0xf0, 0xcc, 0xdb, 0xdc, 0x56, 0xac, 0xf8, 0x21, 0xa1, 0xff, 0x31, 0xa0, 0xff, 0x1a, 0x22, 0x3a, 0x31, 0x01, 0x2c, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x21, 0x9d, 0xff, 0x1c, 0x03, 0x1a, 0x22, 0x01, 0x9e, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x2d, 0x0c, 0x91, 0xc8, 0xff, 0x9a, 0x11, 0x08, 0x71, 0xc8, 0x61, 0xd8, 0x51, 0xe8, 0x41, 0xf8, 0x31, 0x12, 0xc1, 0x20, 0x0d, 0xf0, 0x00, 0x02, 0x00, 0x60, 0x00, 0x00, 0x00, 0x10, 0x40, 0x02, 0x00, 0x60, 0xff, 0xff, 0xff, 0x00, 0x12, 0xc1, 0xe0, 0x0c, 0x02, 0x29, 0x01, 0x31, 0xfa, 0xff, 0x21, 0xfa, 0xff, 0x02, 0x61, 0x07, 0xc9, 0x61, 0xdb, 0xdc, 0x20, 0x00, 0x22, 0x63, 0x00, 0xdb, 0xdc, 0x20, 0x00, 0xc8, 0x03, 0x20, 0xcc, 0x10, 0x56, 0x4c, 0xff, 0x21, 0xf5, 0xff, 0xdb, 0xdc, 0x20, 0x00, 0x38, 0x02, 0x21, 0xf4, 0xff, 0x20, 0x23, 0x10, 0x29, 0x01, 0x0c, 0x43, 0x2d, 0x01, 0x01, 0x85, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x08, 0x71, 0x2d, 0x0c, 0xc8, 0x61, 0x12, 0xc1, 0x20, 0x0d, 0xf0, 0x00, 0x80, 0xfe, 0x3f, 0x84, 0x49, 0x00, 0x40, 0x12, 0xc1, 0xd0, 0xc9, 0xa1, 0x09, 0xb1, 0x7c, 0xfc, 0x22, 0xc1, 0x11, 0x0c, 0x13, 0xc5, 0x1c, 0x00, 0x26, 0x12, 0x02, 0x46, 0x30, 0x00, 0x22, 0x01, 0x11, 0xc2, 0x41, 0x10, 0xb6, 0x82, 0x02, 0x46, 0x2b, 0x00, 0x31, 0xf5, 0xff, 0x30, 0x22, 0xa0, 0x28, 0x02, 0xa0, 0x02, 0x00, 0x2d, 0x01, 0x1c, 0x03, 0x85, 0x1a, 0x00, 0x66, 0x82, 0x0b, 0x28, 0x01, 0x32, 0x21, 0x01, 0xc5, 0xaf, 0xff, 0x06, 0x07, 0x00, 0x00, 0x3c, 0x12, 0x86, 0x05, 0x00, 0x00, 0x10, 0x21, 0x20, 0x32, 0xa0, 0x10, 0x85, 0x18, 0x00, 0x66, 0xa2, 0x0f, 0x22, 0x21, 0x00, 0x38, 0x11, 0x48, 0x21, 0xc5, 0xbc, 0xff, 0x22, 0x41, 0x10, 0x86, 0x1a, 0x00, 0x4c, 0x12, 0x06, 0xfd, 0xff, 0x10, 0x21, 0x20, 0x32, 0xa0, 0x10, 0x85, 0x16, 0x00, 0x66, 0xa2, 0x0c, 0x22, 0x21, 0x00, 0x38, 0x11, 0x48, 0x21, 0x05, 0xd8, 0xff, 0xc6, 0xf6, 0xff, 0x5c, 0x12, 0x86, 0xf5, 0xff, 0x00, 0x10, 0x21, 0x20, 0x32, 0xa0, 0x10, 0x85, 0x14, 0x00, 0x66, 0xa2, 0x0d, 0x22, 0x21, 0x00, 0x38, 0x11, 0x48, 0x21, 0x05, 0xe1, 0xff, 0x06, 0xef, 0xff, 0x00, 0x22, 0xa0, 0x61, 0x46, 0xed, 0xff, 0x45, 0xf0, 0xff, 0xc6, 0xeb, 0xff, 0x00, 0x00, 0x01, 0xd2, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x06, 0xe9, 0xff, 0x00, 0x0c, 0x02, 0x22, 0x41, 0x10, 0x0c, 0x13, 0x22, 0xc1, 0x10, 0xc5, 0x0f, 0x00, 0x22, 0x01, 0x11, 0x06, 0x06, 0x00, 0x00, 0x00, 0x22, 0xc1, 0x10, 0x0c, 0x13, 0xc5, 0x0e, 0x00, 0x22, 0x01, 0x11, 0x32, 0xc2, 0xfa, 0x30, 0x30, 0x74, 0xb6, 0x23, 0x02, 0x06, 0xc8, 0xff, 0x08, 0xb1, 0xc8, 0xa1, 0x12, 0xc1, 0x30, 0x0d, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x4f, 0x48, 0x41, 0x49, 0x00, 0x75, 0x19, 0x03, 0x10, 0x27, 0x00, 0x00, 0x00, 0x11, 0x00, 0x40, 0xa8, 0x10, 0x00, 0x40, 0xbc, 0x0f, 0x00, 0x40, 0x58, 0x3f, 0x00, 0x40, 0xcc, 0x2e, 0x00, 0x40, 0x1c, 0xe2, 0x00, 0x40, 0xd8, 0x39, 0x00, 0x40, 0x80, 0x00, 0x00, 0x40, 0x21, 0xf4, 0xff, 0x12, 0xc1, 0xe0, 0xc9, 0x61, 0xc8, 0x02, 0x21, 0xf2, 0xff, 0x09, 0x71, 0x29, 0x01, 0x0c, 0x02, 0xd9, 0x51, 0xc9, 0x11, 0x01, 0xf4, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x01, 0xf3, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0xac, 0x2c, 0x22, 0xa3, 0xe8, 0x01, 0xf2, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x21, 0xea, 0xff, 0xdb, 0xdc, 0x31, 0x41, 0x2a, 0x23, 0x3d, 0x0c, 0x01, 0xef, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x3d, 0x02, 0x22, 0xa0, 0x00, 0x01, 0xed, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0xc1, 0xe4, 0xff, 0x2d, 0x0c, 0x01, 0xe8, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x2d, 0x01, 0x32, 0xa0, 0x04, 0x45, 0x04, 0x00, 0xc5, 0xe7, 0xff, 0xdd, 0x02, 0x2d, 0x0c, 0x01, 0xe3, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x66, 0x6d, 0x1f, 0x4b, 0x21, 0x31, 0xdc, 0xff, 0x46, 0x00, 0x00, 0x4b, 0x22, 0xdb, 0xdc, 0x20, 0x00, 0x48, 0x02, 0x37, 0x94, 0xf5, 0x31, 0xd9, 0xff, 0xdb, 0xdc, 0x20, 0x00, 0x39, 0x02, 0x3d, 0xf0, 0x86, 0x01, 0x00, 0x00, 0x01, 0xdc, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x08, 0x71, 0xc8, 0x61, 0xd8, 0x51, 0x12, 0xc1, 0x20, 0x0d, 0xf0, 0x00, 0x00, 0x00, 0x12, 0xc1, 0xf0, 0x02, 0x61, 0x03, 0x01, 0x0c, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x08, 0x31, 0x12, 0xc1, 0x10, 0x0d, 0xf0, 0x00, 0x64, 0x3b, 0x00, 0x40, 0x12, 0xc1, 0xd0, 0xe9, 0x81, 0x09, 0xb1, 0xc9, 0xa1, 0xd9, 0x91, 0xf9, 0x71, 0x29, 0x01, 0x39, 0x11, 0xe2, 0xa0, 0xdb, 0xdc, 0x01, 0xfa, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0xcd, 0x02, 0xe7, 0x92, 0xf4, 0x0c, 0x0d, 0xe2, 0xa0, 0xdb, 0xdc, 0xf2, 0xa0, 0xdb, 0xdd, 0x86, 0x0d, 0x00, 0x00, 0x00, 0x01, 0xf4, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x20, 0x42, 0x20, 0xe7, 0x12, 0x40, 0xf7, 0x92, 0x1c, 0x22, 0x61, 0x02, 0x01, 0xef, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0x52, 0xa0, 0xdc, 0x48, 0x21, 0x57, 0x12, 0x09, 0x52, 0xa0, 0xdd, 0x57, 0x12, 0x05, 0x46, 0x05, 0x00, 0x00, 0x4d, 0x0c, 0x38, 0x01, 0xda, 0x23, 0x42, 0x42, 0x00, 0x1b, 0xdd, 0x38, 0x11, 0x37, 0x9d, 0xc5, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0d, 0xc2, 0xa0, 0xdb, 0xdc, 0x01, 0xe3, 0xff, 0xdb, 0xdc, 0x00, 0x00, 0xc7, 0x92, 0xf6, 0x08, 0xb1, 0x2d, 0x0d, 0xc8, 0xa1, 0xd8, 0x91, 0xe8, 0x81, 0xf8, 0x71, 0x12, 0xc1, 0x30, 0x0d, 0xf0, 0x00, 0x00, 0xc0 };
            txFrame19 = new byte[] { 0xc0, 0x00, 0x05, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x80, 0xfe, 0x3f, 0xc0 };
            txFrame20 = new byte[] { 0xc0, 0x00, 0x07, 0x30, 0x00, 0xea, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x05, 0x10, 0x40, 0x7e, 0x05, 0x10, 0x40, 0x9f, 0x05, 0x10, 0x40, 0xbe, 0x05, 0x10, 0x40, 0xde, 0x05, 0x10, 0x40, 0xe6, 0x05, 0x10, 0x40, 0xf0, 0x05, 0x10, 0x40, 0xf0, 0x05, 0x10, 0x40, 0xc0 };
            txFrame21 = new byte[] { 0xc0, 0x00, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x06, 0x10, 0x40, 0xc0 };
            txFrame_File1 = new byte[] { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc0 };//eagle.flash.bin
            txFrame_File2 = new byte[] { 0xc0, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc0 };//ID.bin            
            txFrame_File3 = new byte[] { 0xc0, 0x00, 0x00, 0x04, 0x00, 0x00, 0x60, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc0 };//eagle.irom0text.bin
            txFrame_File4 = new byte[] { 0xc0, 0x00, 0xdb, 0xdc, 0x3f, 0x00, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc0 };//esp_init_data_default.bin
            txFrame_File5 = new byte[] { 0xc0, 0x00, 0xe0, 0x3f, 0x00, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc0 };//blank.bin


            txFrame_FileParam = new byte[] { 0xc0, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc0 };//Param.bin
            txFrame_Start = new byte[] {0xc0,0x01,0xc0 };
        }
        bool b0xc0 = false;
        byte[] rxList = new byte[1024];
        int rxCount = 0;
        void InitRxFrame()
        {
            b0xc0 = false;
            rxCount = 0;
        }
        public bool DataPacketed(byte rx)
        {
            rxList[rxCount++] = rx;
            if (b0xc0)
            {
                if (rx == 0xc0)
                {
                    Debug.WriteLine(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rxList, 0, rxCount, " "));
                    return true;
                }
            }
            else
            {
                if (rx == 0xc0)
                {
                    b0xc0 = true;                    
                }
                else
                {
                    rxCount = 0;
                }
            }
            return false;
        }
        bool CheckPocket(byte com)
        {
            if (rxList[1] == 0x01 && rxList[0x02] == com)
                return true;
            else
                return false;
        }
        bool WaitPocket()
        {
            InitRxFrame();
            while (true)
            {
                try
                {
                    if (DataPacketed((byte)serialPort1.ReadByte()))
                    {
                        return true;
                    }
                }
                catch// (System.Exception ex)
                {
                    return false;
                }
            }
        }
        bool TxFrameProc(int index)
        {
            byte[] tx;
            switch (index)
            {
                case 2:
                    tx = txFrame2;
                    break;
                case 3:
                    tx = txFrame3;
                    break;
                case 4:
                    tx = txFrame4;
                    break;
                case 5:
                    tx = txFrame5;
                    break;
                case 6:
                    tx = txFrame6;
                    break;
                case 7:
                    tx = txFrame7;
                    break;
                case 8:
                    tx = txFrame8;
                    break;
                case 9:
                    tx = txFrame9;
                    break;
                case 10:
                    tx = txFrame10;
                    break;
                case 11:
                    tx = txFrame11;
                    break;
                case 12:
                    tx = txFrame12;
                    break;
                case 13:
                    tx = txFrame13;
                    break;
                case 14:
                    tx = txFrame14;
                    break;
                case 15:
                    tx = txFrame15;
                    break;
                case 16:
                    tx = txFrame16;
                    break;
                case 17:
                    tx = txFrame17;
                    break;
                case 18:
                    tx = txFrame18;
                    break;
                case 19:
                    tx = txFrame19;
                    break;
                case 20:
                    tx = txFrame20;
                    break;
                case 21:
                    tx = txFrame21;
                    break;
                default:
                    return false;
            }
            serialPort1.Write(tx, 0, tx.Length);
            Debug.WriteLine(WFNetLib.StringFunc.StringsFunction.byteToHexStr(tx, " "));
            InitRxFrame();
            while (bComRead)
            {
                try
                {                    
                    if (DataPacketed((byte)serialPort1.ReadByte()))
                    {
                        if (CheckPocket(tx[2]))
                        {
                            return true;
                        }
                    }
                }
                catch// (System.Exception ex)
                {
                    break;
                }
            }
            return false;
        }
    }
}
